import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

const state = {
  token: '', // 登录token
  showLoading: false // 加载动画
}

const mutations = {
  setToken (state, token) {
    state.token = token
  },
  showLoading (state, value) {
    state.showLoading = value
  }
}
const getters = {
  token (state) {
    if (!state.token) {
      state.token = localStorage.getItem('token')
    }
    return state.token
  }
}

export default new Vuex.Store({
  state, getters, mutations, plugins: [createPersistedState()]
})
